package com.ask.threadcase4;

import javax.swing.plaf.SliderUI;

public class MyRunnable implements Runnable {
    int ticket = 0;

    @Override
    public void run() {
        while (true) {
                if (method()) break;
        }
    }

    private synchronized boolean method() {
        if (ticket == 100)
            return true;
        else {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() +
                    "正在售卖第" + ticket + "张票！！！");
            ticket++;
        }
        return false;
    }
}
